layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form
  ,laydate = layui.laydate
  ,layer = layui.layer
  ,layedit = layui.layedit;

  $("#purchaseId").val(getParameter("id"));
	
	
	
	$("#sub").click(function(){
		if($("#audit").val()==""){
			layer.msg('未做审核操作', {icon: 2}); 
		}else if($("#auditCause").val()==""){
			layer.msg('审核意见不能为空', {icon: 2}); 
		}else if($("#audit").val()==2){
			var url = "../../listenPurchase/findByStockNumber.action";
			var date = {"purchaseId":getParameter("id")};
			$.post(url,date,function(mes){
				if(mes.datas==0){
					layer.msg(mes.msg);
					  setTimeout(() => {
						  window.parent.location.reload()
						  var index=parent.layer.getFrameIndex(window.name);
						  parent.layer.close(index);
						}, 500);
				}else{
					var urls = "../../listenPurchase/updatePurchaseState.action";
					var dates ={"auditingStatus":$("#audit").val(),"purchaseId":getParameter("id")};
					$.post(urls,dates,function(mess){
						if(mess.datas == 0){
							 layer.msg(mess.msg);
							  setTimeout(() => {
								  window.parent.location.reload()
								  var index=parent.layer.getFrameIndex(window.name);
								  parent.layer.close(index);
								}, 500);
						}
					},"json")
				}
				var index = layer.load(0, {
		  			  shade: [0.1,'#fff'] //0.1透明度的白色背景
		  		});
				//调用增加到审核的方法
				sumbitFrom();
			},"json")
		}else if($("#audit").val()==4){
			var index = layer.load(0, {
	  			  shade: [0.1,'#fff'] //0.1透明度的白色背景
	  		});
			//调用增加到审核的方法
			sumbitFrom();
			var url = "../../listenPurchase/updatePurchaseState.action";
			var date ={"auditingStatus":$("#audit").val(),"purchaseId":getParameter("id")};
			$.post(url,date,function(mes){
				if(mes.datas == 0){
					layer.msg(mes.msg);
					  setTimeout(() => {
						  window.parent.location.reload()
						  var index=parent.layer.getFrameIndex(window.name);
						  parent.layer.close(index);
						}, 500);
				}
			},"json")
		}
		
	})
	
	
  
  
});


layui.use('upload', function(){
	  var $ = layui.jquery
	  ,upload = layui.upload;
});
function load(){
	var form = layui.form;
	form.render();
}
function sumbitFrom(){
	var url="../../listenAuditing/insertPurchaseAudit.action";
	var data=$("#myform").serialize();
	$.post(url,data,function(mes){
		
	},"json")
}
/*function myrefresh() {
	parent.location.href="../../pages/purchaseMusicAudit/purchaseMusicAudit.html";
} */
/**
 * 从地址栏传值的代码
 * @param param
 * @returns
 */
function getParameter(param){
	var query = window.location.search;
	var iLen = param.length;
	var iStart = query.indexOf(param);
	if (iStart == -1)
		return "";
	iStart += iLen + 1;
	var iEnd = query.indexOf("&", iStart);
	if (iEnd == -1)
		return query.substring(iStart);
	return query.substring(iStart, iEnd);
}